package com.water.camera.mark;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.water.camera.bean.EditItem;
import com.water.camera.databinding.LayoutWatermark88Binding;

import java.text.SimpleDateFormat;
import java.util.ArrayList;

public class Mark88 extends BaseMark {

    LayoutWatermark88Binding binding;

    public Mark88(@NonNull Context context) {
        super(context);
    }

    public Mark88(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public Mark88(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void init(int type) {
        if (type == 0) {
            binding = LayoutWatermark88Binding.inflate(LayoutInflater.from(getContext()));
            addView(binding.getRoot());
            hideView(binding.binding9, binding.binding11);
        } else {
            binding = LayoutWatermark88Binding.inflate(LayoutInflater.from(getContext()), this, true);
        }
        update();
    }

    @Override
    public void update() {
        setText(binding.binding2, "jingwei88", binding.binding1);
        String[] ss = new EditItem("jingwei88").getStringPoints();
        binding.binding2.setText(ss[1]);
        binding.binding4.setText(ss[0]);

        setText(binding.binding6, "didian88", binding.binding5);

        setText(binding.binding8, "time88", binding.binding7);
        setTime(binding.binding8, new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
        setText(binding.binding10, "beizhu88", binding.binding9);


        setText(binding.binding12, "tip88", binding.binding10);


        super.update();
    }

    @Override
    public ArrayList<EditItem> getEditItems() {
        ArrayList<EditItem> list = new ArrayList<>();
        list.add(new EditItem("jingwei88", "经纬度"));
        list.add(new EditItem("didian88", "地点"));

        list.add(new EditItem("time88", "时间", true));

        list.add(new EditItem("beizhu88", "备注"));
        list.add(new EditItem("operator88", "提示语"));


        return list;
    }

    @Override
    public void onValueChange(EditItem item) {
        if (item.isTime) {
            setTime(binding.binding8, new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
        } else if (item.isPoint()) {
            String[] ss = new EditItem("jingwei88").getStringPoints();
            binding.binding2.setText(ss[1]);
            binding.binding4.setText(ss[0]);
        } else {
            super.onValueChange(item);
        }
    }

    @Override
    public void onShowChange(EditItem item) {
        if (item.isPoint()) {
            if (item.show) {
                showView(binding.binding1, binding.binding3);
            } else {
                hideView(binding.binding1, binding.binding3);
            }
        } else {
            super.onShowChange(item);
        }
    }
}
